﻿using System;
using System.Windows;

namespace WITD
{
    /// <summary>
    /// Interaction logic for NewWITName.xaml.
    /// <para></para><para></para>
    /// Allows entry of a new WITD name for renaming a WITD.
    /// </summary>
    public partial class NewWITName : Window
    {
        private String _currentName;
        private String _newName;

        /// <summary>
        /// The current name of the work item type.
        /// </summary>
        public String Currentname
        {
            get
            {
                return _currentName;
            }
        }

        /// <summary>
        /// The new name for the work item type.
        /// </summary>
        public String NewName
        {
            get
            {
                return _newName;
            }
        }

        /// <summary>
        /// Constructor that accepts the current name of the work item type to display.
        /// </summary>
        /// <param name="currentName">The current name of the work item type.</param>
        /// <param name="parent">The owning Window object instance. It must have been shown at least once to avoid an Exception.</param>
        public NewWITName(String currentName, Window parent)
        {
            InitializeComponent();
            _currentName = currentName;
            Owner = parent;
            txtCurrentName.Text = _currentName;
            txtCurrentName.IsReadOnly = true;
            txtNewName.Focus();
        }

        /// <summary>
        /// Captures and stores the new name for the work item type and closes the Window.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnOkay_Click(object sender, RoutedEventArgs e)
        {
            if (!String.IsNullOrEmpty(txtNewName.Text))
            {
                this.DialogResult = true;
                _newName = txtNewName.Text;
                this.Close();
            }
        }

        /// <summary>
        /// Cancels the rename operation and closes the window.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnCancel_Click(object sender, RoutedEventArgs e)
        {
            DialogResult = false;
            Close();
        }
    }
}
